package com.ruoyi.project.system.achievement.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.achievement.domain.ArticleAchievement;
import com.ruoyi.project.system.achievement.service.IArticleAchievementService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * achievementController
 * 
 * @author admin
 * @date 2025-04-24
 */
@Controller
@RequestMapping("/cross/achievement")
public class ArticleAchievementController extends BaseController
{
    private String prefix = "cross/achievement";

    @Autowired
    private IArticleAchievementService articleAchievementService;

    @RequiresPermissions("cross:achievement:view")
    @GetMapping()
    public String achievement()
    {
        return prefix + "/achievement";
    }

    /**
     * 查询achievement列表
     */
    @RequiresPermissions("cross:achievement:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ArticleAchievement articleAchievement)
    {
        startPage();
        List<ArticleAchievement> list = articleAchievementService.selectArticleAchievementList(articleAchievement);
        return getDataTable(list);
    }

    /**
     * 导出achievement列表
     */
    @RequiresPermissions("cross:achievement:export")
    @Log(title = "achievement", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ArticleAchievement articleAchievement)
    {
        List<ArticleAchievement> list = articleAchievementService.selectArticleAchievementList(articleAchievement);
        ExcelUtil<ArticleAchievement> util = new ExcelUtil<ArticleAchievement>(ArticleAchievement.class);
        return util.exportExcel(list, "achievement数据");
    }

    /**
     * 新增achievement
     */
    @RequiresPermissions("cross:achievement:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存achievement
     */
    @RequiresPermissions("cross:achievement:add")
    @Log(title = "achievement", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ArticleAchievement articleAchievement)
    {
        return toAjax(articleAchievementService.insertArticleAchievement(articleAchievement));
    }

    /**
     * 修改achievement
     */
    @RequiresPermissions("cross:achievement:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ArticleAchievement articleAchievement = articleAchievementService.selectArticleAchievementById(id);
        mmap.put("articleAchievement", articleAchievement);
        return prefix + "/edit";
    }

    /**
     * 修改保存achievement
     */
    @RequiresPermissions("cross:achievement:edit")
    @Log(title = "achievement", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ArticleAchievement articleAchievement)
    {
        return toAjax(articleAchievementService.updateArticleAchievement(articleAchievement));
    }

    /**
     * 删除achievement
     */
    @RequiresPermissions("cross:achievement:remove")
    @Log(title = "achievement", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(articleAchievementService.deleteArticleAchievementByIds(ids));
    }
}
